<?php
class PublicAction extends BaseAction
{
    /**
     * 后台登陆操作
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function login()
    {
        if ($this->ispost()) {
            $map = array();
            $email = $this->_post('email');
            $pwd = $this->_post('pwd');
            $verify = $this->_post('verify');
            if ($_SESSION['verify'] != md5($_POST['verify'])) {
                $this->error('验证码错误！');
            } else {
                $map['email'] = $email;
                $map['pwd'] = md5($pwd);
                $UserModel = D('Users');
                $user = $UserModel->field('id,name,email')
                        ->where($map)
                        ->find();
                if ($user) {
                    //权限认证提供操作
                    $_SESSION[C('USER_AUTH_KEY')] = $user['id'];
                    //进行日志登陆记录
                    $log['sql'] = $UserModel->getLastSql();
                    $log['key'] = $user['id'];
                    $UserModel->logWrite(4, $log);
                    //修改登陆时间
                    $data['id'] = $user['id'];
                    $data['last_login_time'] = time();
                    $data['last_login_ip'] = get_client_ip();
                    $UserModel->save($data);
                    //登录状态记录
                    setOnline($user['id']);
                    //记录登陆次数
                    addUserLoginCount($user['id']);
                    $url = __APP__;
                    redirect($url);
                } else {
                    $this->error($email . '信息错误登陆失败！');
                }
            }
        }
        $this->display();
    }

    public function loginOut()
    {
        unset($_SESSION);
        Session::destroy();
        redirect(SITE_URL);
    }

    Public function verify()
    {
        import("@.ORG.Util.Image");
        Image::buildImageVerify();
    }
}

?>